package day15;

import java.util.Comparator;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class GenericDemo {

	public static void main(String[] args) {
		get_worker();
		System.out.println("****************");
		get_teacher();
	}
	
	
	
	public static void get_teacher() {
		Set<Teacher> set = new TreeSet<Teacher>(new PersonComparator());
		set.add(new Teacher("java01",01));
		set.add(new Teacher("java",01));
		set.add(new Teacher("java08",01));
		set.add(new Teacher("javaa",01));
		set.add(new Teacher("javab",01));
		for (Iterator<Teacher> iterator = set.iterator(); iterator.hasNext();) {
			Teacher teacher = iterator.next();
			System.out.println(teacher);
		}
	}
	public static void get_worker() {
		Set<Worker> set = new TreeSet<Worker>(new PersonComparator());
		set.add(new Worker("worker01",01));
		set.add(new Worker("workerjava",01));
		set.add(new Worker("workerjava08",01));
		set.add(new Worker("workerjavaa",01));
		set.add(new Worker("workerjavab",01));
		for (Iterator<Worker> iterator = set.iterator(); iterator.hasNext();) {
			Worker worker = iterator.next();
			System.out.println(worker);
		}
	}
}

//定义一个Person的比较器，可以比较工人和老师
class PersonComparator implements Comparator<Person> {

	@Override
	public int compare(Person o1, Person o2) {
		return o1.getName().compareTo(o2.getName());
	}
	
}